package fr.bda.cloud.storage;

import java.io.File;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import fr.bda.cloud.storage.StorageUnitConfiguration;
import fr.bda.cloud.storage.StorageUnitType;

@XmlRootElement
public class LocalStorageUnitConfiguration extends StorageUnitConfiguration {

	private File localFolder;

	public LocalStorageUnitConfiguration() {
		super(StorageUnitType.LOCAL);
	}

	public LocalStorageUnitConfiguration(File f){
		super(StorageUnitType.LOCAL);
		this.localFolder = f;
		
	}
	@XmlElement(name = "local_folder")
	public File getLocalFolder() {
		return localFolder;
	}

	public void setLocalFolder(File localPathFolder) {
		this.localFolder = localPathFolder;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((localFolder == null) ? 0 : localFolder.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		LocalStorageUnitConfiguration other = (LocalStorageUnitConfiguration) obj;
		if (localFolder == null) {
			if (other.localFolder != null)
				return false;
		} else if (!localFolder.equals(other.localFolder))
			return false;
		return true;
	}

	@Override
	public String toString() {
		int maxPathLength = 45;
		String subPath = localFolder.getAbsolutePath();
		if (subPath.length() > maxPathLength){
			subPath = "..." + subPath.substring(subPath.length() - maxPathLength, subPath.length());
		}
		return "LS > " + subPath;
	}

}
